package com.cloudeye.bus.manage.web;

import com.alibaba.nacos.api.config.annotation.NacosValue;
import com.alibaba.nacos.spring.context.annotation.config.NacosPropertySource;
import com.cloudeye.bus.model.Result;
import com.cloudeye.business.mq.config.RabbitMqMsgTypeEnum;
import com.cloudeye.business.mq.model.MqMsg;
import com.cloudeye.business.mq.service.MqMsgSenderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

/**
 * Created by lafangyuan on 2021/1/18.
 */
@RestController
@RequestMapping("/bus")
@RefreshScope
public class BusController {

//    @NacosValue(value = "${bus.busStationCode}",autoRefreshed = true)
    private String busStationCode;

//    @Value("${bus.busStationCode}")
    private String busStationCode1;

    @Autowired
    MqMsgSenderService mqMsgSenderService;

    @GetMapping("/hello")
    public Result hello(){
        MqMsg mqMsg = new MqMsg();
        mqMsg.setMsgId("1");
        mqMsg.setBody("hello");
        mqMsg.setSendTime(new Date());
        mqMsgSenderService.send(RabbitMqMsgTypeEnum.IM_USER_ADD,mqMsg);
        return Result.sussess();
    }

    @GetMapping("/getNacosProp")
    public Result getNacosProp(){
        return Result.sussess(busStationCode);
    }

    @GetMapping("/getNacosCloudProp")
    public Result getNacosCloudProp(){
        return Result.sussess(busStationCode1);
    }
}
